package com.ihuipao.game.Objects;

import android.media.ExifInterface;

public class Exif {
    private String path;
    private String model;// = exif.getAttribute(ExifInterface.TAG_MAKE);
    private String make;// = exif.getAttribute(ExifInterface.TAG_MODEL);
    private String dateTime;// = exif.getAttribute(ExifInterface.TAG_DATETIME);
    private String orientation;// = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
    private String flash;// = exif.getAttribute(ExifInterface.TAG_FLASH);
    private String focalLength;// = exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
    private String iso;// = exif.getAttribute(ExifInterface.TAG_ISO);
    private String shutterSpeed;// = exif.getAttribute(ExifInterface.TAG_SHUTTER_SPEED_VALUE);
    private String aperture;// = exif.getAttribute(ExifInterface.TAG_APERTURE);
    private String exposureTime;// = exif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
    private String uniqid;//
    public Exif(String path){
        this.path = path;
        try{
            ExifInterface exif = new ExifInterface(path);
            this.model = exif.getAttribute(ExifInterface.TAG_MAKE);
            this.make = exif.getAttribute(ExifInterface.TAG_MODEL);
            this.dateTime = exif.getAttribute(ExifInterface.TAG_DATETIME);
            this.orientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
            this.flash = exif.getAttribute(ExifInterface.TAG_FLASH);
            this.focalLength = exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
            this.iso = exif.getAttribute(ExifInterface.TAG_ISO);
            this.shutterSpeed = exif.getAttribute(ExifInterface.TAG_SHUTTER_SPEED_VALUE);
            this.aperture = exif.getAttribute(ExifInterface.TAG_APERTURE);
            this.exposureTime = exif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
            this.uniqid = exif.getAttribute(ExifInterface.TAG_IMAGE_UNIQUE_ID);
        }catch (Exception exception){

        }
    }

    public String getModel() {
        return model==null ? "" : model;
    }

    public String getMake() {
        return make==null ? "" : make;
    }

    public String getDateTime() {
        return dateTime == null ? "" : formatDate(dateTime);
    }

    public String getOrientation() {
        return orientation==null ? "" : orientation;
    }

    public String getFlash() {
        return flash==null ? "" : flash;
    }

    public String getFocalLength() {
        return focalLength==null ? "" : focalLength;
    }

    public String getIso() {
        return iso==null ? "" : iso;
    }

    public String getShutterSpeed() {
        return shutterSpeed==null ? "" : shutterSpeed;
    }

    public String getAperture() {
        return aperture==null? "" : aperture;
    }

    public String getExposureTime() {
        return exposureTime==null ? "" : formatDate(exposureTime);
    }

    public String getUniqid(){
        return uniqid==null ? "" : uniqid;
    }

    private String formatDate(String date){
        if(date.contains(" ")){
            String[] split = date.split(" ");
            split[0] = split[0].replaceFirst(":", "-");
            split[0] = split[0].replaceFirst(":", "-");
            return String.format("%s %s", split[0], split[1]);
        }else{
            return date;
        }
    }
}
